package cn.songtx.iot.controller;

import cn.songtx.iot.pojo.Result;
import cn.songtx.iot.service.MqttGateWayService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mqtt")
@RequiredArgsConstructor
public class MqttPubController {

    @Autowired
    private MqttGateWayService mqttGateWayService;

    /**
     * 发送MQTT消息
     *
     * @param topic 主题
     * @param msg   消息
     * @return 统一的Result
     */
    @RequestMapping(value = "/publish", method = RequestMethod.GET)
    public Result sendMsg(String topic, String msg) {
        mqttGateWayService.publishMqtt(topic, msg);
        return Result.success("发送成功");
    }
}
